package homework.exp03;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class G {
    static Scanner cin = null;

    static {
        try {
            cin = new Scanner(new FileReader(new File("G.in")));
        } catch (IOException e) {
            cin = new Scanner(System.in);
        }
    }

    static String words;
    static int pos = 0;
    static char ch;
    static int no = 1;

    public static void main(String[] args) {

        while (cin.hasNextLine()) {
            words = cin.nextLine();
            if (words.equals("EOF")) {
                break;
            }
            pos = 0;
            no = 1;
            ch = words.charAt(pos);
            if (exp()) {
                if (ch == '#') {
                    System.out.println("syntax correct");
                } else {
                    System.out.println("syntax error");
                }
            } else {
                System.out.println("syntax error");
            }
        }
        cin.close();
    }

    // E->TE'
    static boolean exp() {
        if (!term()) {
            return false;
        }
        return expA();
    }

    // E'->+TE'|;
    static boolean expA() {
        if (ch == '+') {
            advance();
            if (!term()) {
                return false;
            }
            return expA();
        } else {
            return true;
        }
    }

    // T->FT'
    static boolean term() {
        if (!factor()) {
            return false;
        }
        return termA();
    }

    // T'->*FT'|;
    static boolean termA() {
        if (ch == '*') {
            advance();
            if (!factor()) {
                return false;
            }
            return termA();
        } else {
            return true;
        }
    }

    // F->(E)|i
    static boolean factor() {
        if (ch == '(') {
            advance();
            if (!exp()) {
                return false;
            }
            if (ch == ')') {
                advance();
                return true;
            } else {
                return false;
            }
        } else if (ch == 'i') {
            advance();
            return true;
        } else {
            return false;
        }
    }

    static void advance() {
        if (pos < words.length() - 1) {
            pos++;
            ch = words.charAt(pos);
        } else {
            ch = '#';
        }
    }
}